home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_kernel_source / IPC / UTIL.C < prev   
C/C++ Source or Header  |  1999-09-17  |  3KB  |  127 lines

  1. /*
  2.  * linux/ipc/util.c
  3.  * Copyright (C) 1992 Krishna Balasubramanian
  4.  *
  5.  * Sep 1997 - Call suser() last after "normal" permission checks so we
  6.  *            get BSD style process accounting right.
  7.  *            Occurs in several places in the IPC code.
  8.  *            Chris Evans, <chris@ferret.lmh.ox.ac.uk>
  9.  */
  10.  
  11. #include <linux/config.h>
  12. #include <linux/mm.h>
  13. #include <linux/shm.h>
  14. #include <linux/init.h>
  15. #include <linux/msg.h>
  16.  
  17. #if defined(CONFIG_SYSVIPC)
  18.  
  19. extern void sem_init (void), msg_init (void), shm_init (void);
  20.  
  21. void __init ipc_init (void)
  22. {
  23.     sem_init();
  24.     msg_init();
  25.     shm_init();
  26.     return;
  27. }
  28.  
  29. /* 
  30.  * Check user, group, other permissions for access
  31.  * to ipc resources. return 0 if allowed
  32.  */
  33. int ipcperms (struct ipc_perm *ipcp, short flag)
  34. {    /* flag will most probably be 0 or S_...UGO from <linux/stat.h> */
  35.     int requested_mode, granted_mode;
  36.  
  37.     requested_mode = (flag >> 6) | (flag >> 3) | flag;
  38.     granted_mode = ipcp->mode;
  39.     if (current->euid == ipcp->cuid || current->euid == ipcp->uid)
  40.         granted_mode >>= 6;
  41.     else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
  42.         granted_mode >>= 3;
  43.     /* is there some bit set in requested_mode but not in granted_mode? */
  44.     if ((requested_mode & ~granted_mode & 0007) && 
  45.         !capable(CAP_IPC_OWNER))
  46.         return -1;
  47.  
  48.     return 0;
  49. }
  50.  
  51. #else
  52. /*
  53.  * Dummy functions when SYSV IPC isn't configured
  54.  */
  55.  
  56. void sem_exit (void)
  57. {
  58.     return;
  59. }
  60.  
  61. int shm_swap (int prio, int gfp_mask)
  62. {
  63.     return 0;
  64. }
  65.  
  66. asmlinkage int sys_semget (key_t key, int nsems, int semflg)
  67. {
  68.     return -ENOSYS;
  69. }
  70.  
  71. asmlinkage int sys_semop (int semid, struct sembuf *sops, unsigned nsops)
  72. {
  73.     return -ENOSYS;
  74. }
  75.  
  76. asmlinkage int sys_semctl (int semid, int semnum, int cmd, union semun arg)
  77. {
  78.     return -ENOSYS;
  79. }
  80.  
  81. asmlinkage int sys_msgget (key_t key, int msgflg)
  82. {
  83.     return -ENOSYS;
  84. }
  85.  
  86. asmlinkage int sys_msgsnd (int msqid, struct msgbuf *msgp, size_t msgsz, int msgflg)
  87. {
  88.     return -ENOSYS;
  89. }
  90.  
  91. asmlinkage int sys_msgrcv (int msqid, struct msgbuf *msgp, size_t msgsz, long msgtyp,
  92.                int msgflg)
  93. {
  94.     return -ENOSYS;
  95. }
  96.  
  97. asmlinkage int sys_msgctl (int msqid, int cmd, struct msqid_ds *buf)
  98. {
  99.     return -ENOSYS;
  100. }
  101.  
  102. asmlinkage int sys_shmget (key_t key, int size, int flag)
  103. {
  104.     return -ENOSYS;
  105. }
  106.  
  107. asmlinkage int sys_shmat (int shmid, char *shmaddr, int shmflg, ulong *addr)
  108. {
  109.     return -ENOSYS;
  110. }
  111.  
  112. asmlinkage int sys_shmdt (char *shmaddr)
  113. {
  114.     return -ENOSYS;
  115. }
  116.  
  117. asmlinkage int sys_shmctl (int shmid, int cmd, struct shmid_ds *buf)
  118. {
  119.     return -ENOSYS;
  120. }
  121.  
  122. void shm_unuse(unsigned long entry, unsigned long page)
  123. {
  124. }
  125.  
  126. #endif /* CONFIG_SYSVIPC */
  127.